//
//  HMMainViewController.swift
//  WeiboPre12
//
//  Created by EnjoySR on 15/12/25.
//  Copyright © 2015年 EnjoySR. All rights reserved.
//

import UIKit

class TFMainTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = TFTabBar()
        tabBar.composeButtonClickClourse = {
            print("撰写按钮点击")
        }
        setValue(tabBar, forKey: "tabBar")
        addChildViewControllers()
    }
    
    /// 添加所有子控制器
    private func addChildViewControllers() {
        addChildViewController(TFHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(TFMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(TFDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(TFProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    /// 添加控制器
    ///
    /// - parameter vc       : 视图控制器
    /// - parameter title    : 标题
    /// - parameter imageName: 图像名称
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        //设置标题
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //文字颜色的属性
        let textColorAttr = [
            NSForegroundColorAttributeName: UIColor.orangeColor()
        ]
        //设置选中文字颜色
        vc.tabBarItem.setTitleTextAttributes(textColorAttr, forState: UIControlState.Selected)
        
        //使用导航控制器包裹起来
        let nav = TFNavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
}
